import socket
import time
from datetime import datetime, timedelta
from math import ceil

def now2():
    host = "49.232.134.204"

    s = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)

    time.sleep(1)

    s.sendto(bytes(bytearray([-29 + 256] + [0 for i in range(47)])), (host, 123))

    msg, _ = s.recvfrom(48)
    
    time.sleep(1)

    timestamp = 0
    for x in msg[40:44]:
        timestamp = 256 * timestamp + x

    timestamp -= 2208988800

    return datetime.utcfromtimestamp(timestamp) + timedelta(hours=8)

start = time.time()
print(now2())
print(datetime.now())
print('cost %fs' % (time.time()-start))